• The function findNext(theString) goes to the next card containing the string. It uses the find command because its so fast. It counts the number of cards the string has been found on, and lets you do whatever you want on each card it finds. findNext keeps track of the first card it found and tells you when you've gone all the way around the stack.
To use findNext, declare "numberFound" to be a global variable. Set it to zero.
FindNext("Abe") will return true if it found a new card with "Abe" on it. It returns false if there are no more cards with "Abe". Each time,
"numberFound" has the number of cards "Abe" was found on.
Example: Put this into your button script.
on mouseUp
--an example of using findNext()
--count the number of cards with a word starting with "Abe" or whatever
global numberFound
put 0 into numberFound
repeat while findNext("Abe") --"Abe" or whatever you choose
end repeat
put "Found on" && numberFound && "cards" into message
end mouseUp
Put this into your stack script.
function findNext key
--fast searching of a stack under program control. see example.
--return true if we found a new occurance, false if done
--numberFound will have the total we have found
global numberFound, firstFound
if (numberFound = 0) or (firstFound is empty)
then return findFirst(key)
go next card
find key
if the result is "not found" then
put empty into firstFound
return false
end if
if the ID of this card <> firstFound then
add 1 to numberFound
return true --we found another occurance
else --we wrapped around the stack
put empty into firstFound
return false
end if
end findNext
function findFirst key
--only called by findNext (not called by user)
--because numberFound = 0, we know this is the first time
global numberFound, firstFound
if numberFound <> 0 then
ask "You must put 0 into numberFound before calling findNext()"¬with "OK"
return false
end if
find key
if the result is "not found" then
put empty into firstFound
return false
else --we found it
put the ID of this card into firstFound
put 1 into numberFound
return true
end if
end findFirst
You can put findNext() and its subroutine, findFirst(), into your home script. If you have stricter conditions on the cards you want to find, do your tests on each card that findNext finds.